<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>智联同城——代理管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  
  <link rel="stylesheet" href="/Public/layui/css/layui.css"  media="all">
  <style type="text/css">
    
  </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">智联同城</div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <li class="layui-nav-item"><a href="<?php echo U('Index/index');?>">首页</a></li>
      <li class="layui-nav-item"><a href="<?php echo U('InfoCate/index');?>">分类信息管理</a></li>
      <li class="layui-nav-item layui-this"><a href="<?php echo U('ShopCate/index');?>">好店管理</a></li>
      <li class="layui-nav-item"><a href="<?php echo U('Quan/index');?>">同城圈管理</a></li>
      <li class="layui-nav-item"><a href="<?php echo U('Member/index');?>">用户管理</a></li>
      <li class="layui-nav-item"><a href="<?php echo U('Home/Index/index');?>">切换小程序</a></li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="<?php echo ($_SESSION['wechat']['headimg']); ?>" class="layui-nav-img">
          <?php echo ($_SESSION['wechat']['nickname']); ?>
        </a>
        <dl class="layui-nav-child">
          <dd><a href="<?php echo U('Home/Index/index');?>">切换小程序</a></dd>
          <!-- <dd><a href="">安全设置</a></dd> -->
        </dl>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="<?php echo (session('headimgurl')); ?>" class="layui-nav-img">
          <?php echo (session('nickname')); ?>
        </a>
        <dl class="layui-nav-child">
          <dd><a href="<?php echo U('Home/Public/logout');?>">退出登录</a></dd>
          <!-- <dd><a href="">安全设置</a></dd> -->
        </dl>
      </li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li class="layui-nav-item"><a href="<?php echo U('ShopCate/index');?>">商家分类管理</a></li>
        <li class="layui-nav-item"><a href="<?php echo U('Topic/index');?>">专题管理</a></li>
        <li class="layui-nav-item layui-this"><a href="<?php echo U('Shop/index');?>">商家管理</a></li>
        <li class="layui-nav-item"><a href="<?php echo U('Shop/renlingList');?>">商家认领管理</a></li>
        <li class="layui-nav-item"><a href="<?php echo U('Goods/index');?>">商品管理</a></li>
        <li class="layui-nav-item"><a href="<?php echo U('Coupon/index');?>">优惠券管理</a></li>
        <li class="layui-nav-item"><a href="<?php echo U('Order/index');?>">订单管理</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
      <fieldset class="layui-elem-field layui-field-title">
        <legend>商家管理</legend>
      </fieldset>
      <div style="margin-bottom: 15px;">
        <button id="add" class="layui-btn">添加商家</button>
      </div>
      <form id="form1" name="form1" method="post" action="<?php echo U('Shop/uploadexcel');?>" enctype="multipart/form-data" style="position: relative;left: 9%;top: -54px;">
        导入商家
        <input name="file" type="file"  style="width:70px"/>
        <input type="submit" class="layui-btn"  value="确认导入"/>
      </form>

      <div style="text-align: center;">
        <input id="search-snames" type="text" placeholder="商家名称/联系人/联系电话" style="width: 300px;">
        <select id="search-selsct">
          <option value="0">-请选择-</option>
          <option value="1">置顶</option>
          <option value="2">屏蔽</option>
          <option value="3">待审核</option>
          <option value="4">待认领</option>
        </select>
        <button class="layui-btn" type="submit" id="search-butt">
          <i class="layui-icon">&#xe615;</i> 搜索
        </button>
        <!--<button id="search-butt" class="layui-btn layui-btn-radius" type="submit">搜索</button>-->
      </div>

      <div id="view"></div>
    </div>

  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © 2017-2018 <a href="https://www.58zltc.com" target="_blank">智联同城</a> All Rights Reserved.
  </div>
</div>
<script id="tpl" type="text/html">
  <table class="layui-table">
    <thead>
      <tr>
        <th>ID</th>
        <th>所属分类</th>
        <th>行业模板</th>
        <th>商家名称</th>
        <th>联系人</th>
        <th>联系电话</th>
        <th>到期时间</th>
        <th>操作</th>
      </tr> 
    </thead>
    <tbody>
      {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td>{{ item.shop_id }}</td>
        <td>{{ item.cate }}</td>
        <td>
          {{#  if(item.type == 'car'){ }}
          汽车模板
          {{#  }else if(item.type == 'jiaoyu'){ }}
          教育模板
          {{#  }else if(item.type == 'base'){ }}
          基础模板
          {{#  }else if(item.type == 'jiancai'){ }}
          建材模版
          {{#  }else{ }}
          通用模板
          {{#  } }}
        </td>
        <td>{{ item.name }}</td>
        <td>{{ item.username }}</td>
        <td>{{ item.tel }}</td>
        <td>{{ item.join_end_time }}</td>
        <td>
          {{#  if(item.is_tui == 1){ }}
          <button data-id="{{ item.shop_id }}" data-status="0" class="tui layui-btn layui-btn-small">取消推荐</button>
          {{#  }else{ }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="tui layui-btn layui-btn-small">推荐</button>
          {{#  } }}

          {{#  if(item.status == 0 ){ }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="tong layui-btn layui-btn-small">通过审核</button>
          {{#  } }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="setType layui-btn  layui-btn-normal layui-btn-small">修改模板</button>

          {{#  if(item.is_top == 1){ }}
          <button data-id="{{ item.shop_id }}" data-status="0" class="top" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #212121" >
            取消置顶
          </button>
          {{#  }else{ }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="top" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #212121" >
            置顶
          </button>
          {{#  } }}

          {{#  if(item.has_mini == 0 ){ }}
          <button data-id="{{ item.shop_id }}" class="createmini" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #cccc77" >
            申请生成小程序
          </button>
          {{#  }else if(item.has_mini == 1){ }}
            <button   style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
              color: #fff;
              white-space: nowrap;
              text-align: center;border: none;
              border-radius: 2px;
              cursor: pointer;
              opacity: .9;    background-color: #92B8B1" >
              小程序生成审核中
            </button>
          {{#  }else if(item.has_mini == 2){ }}
          <button data-id="{{ item.shop_id }}" class="mini" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #505050" >
            生成小程序
          </button>
        </td>
        {{#  } }}
        <button data-id="{{ item.shop_id }}" class="del layui-btn layui-btn-small">删除</button>
        <button data-id="{{ item.shop_id }}" class="edit" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #505050" >
          编辑
        </button>
        {{#  if(item.is_shield == 1){ }}
        <button data-id="{{ item.shop_id }}" data-status="0" class="shield" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #ff5722" >
          取消屏蔽
        </button>
        {{#  }else{ }}
        <button data-id="{{ item.shop_id }}" data-status="1" class="shield" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #ff5722" >
          屏蔽
        </button>
        {{#  } }}

      </tr>
      {{#  }); }}
      {{#  if(d.length === 0){ }}
        无数据
      {{#  } }}
    </tbody>
  </table>
  <div id="page-box"></div>
</script>
<script src="/Public/layui/layui.js" charset="utf-8"></script>
<script>
//JavaScript代码区域
layui.use(['element','laypage','laytpl','layer'], function(){
  var element = layui.element
  ,$ = layui.jquery
  ,layer = layui.layer
  ,laypage = layui.laypage
  ,laytpl = layui.laytpl;

  //删除
  $("#view").on('click', '.del', function(event) {
    var id = $(this).data('id');
    if(confirm('确定要删除么')){ //只有当点击confirm框的确定时，该层才会关闭
      $.post("<?php echo U('del');?>", {id: id}, function(e) {
        if(e.status == 1){
          layer.msg(e.info,{icon: 6,time:1000});
          setTimeout("location.reload()",1000);
        }else{
          layer.msg(e.info,{icon:1,time:1000});
        }
      });
    }
  });
  //屏蔽
  $("#view").on('click', '.shield', function(event) {
    var id = $(this).data('id');
    var stauts = $(this).data('status');
    $.post("<?php echo U('shield');?>", {id: id,status:stauts}, function(e) {
      if(e.status == 1){
        layer.msg(e.info,{icon: 6,time:1000});
        setTimeout("location.reload()",1000);
      }else{
        layer.msg(e.info,{icon:1,time:1000});
      }
    });

  });
  //置顶
  $("#view").on('click', '.top', function(event) {
    var id = $(this).data('id');
    var stauts = $(this).data('status');
      $.post("<?php echo U('top');?>", {id: id,status:stauts}, function(e) {
        if(e.status == 1){
          layer.msg(e.info,{icon: 6,time:1000});
          setTimeout("location.reload()",1000);
        }else{
          layer.msg(e.info,{icon:1,time:1000});
        }
      });

  });
  //推荐
  $("#view").on('click', '.tui', function(event) {
    var id = $(this).data('id');
    var status = $(this).data('status');
    $.post("<?php echo U('tui');?>", {id: id, status: status}, function(e) {
      if(e.status == 1){
        layer.msg(e.info,{icon: 6,time:1000});
        setTimeout("location.reload()",1000);
      }else{
        layer.msg(e.info,{icon:1,time:1000});
      }
    });
  });
  //申请生成小程序
  $("#view").on('click', '.createmini', function(event) {
    var id = $(this).data('id');
    layer.open({
      type: 2,
      title: '生成小程序',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      skin: 'layui-layer-rim', //加上边框
      area: ['420px', '240px'], //宽高
      content: '<?php echo U("mini");?>?id='+id
    });

  })

  $("#view").on('click', '.mini', function(event) {
    var id = $(this).data('id');
    /*layer.open({
      type: 2,
      title: '生成小程序',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      skin: 'layui-layer-rim', //加上边框
      area: ['420px', '240px'], //宽高
      content: '<?php echo U("mini");?>?id='+id
    });*/
    $.get("<?php echo U('Shop/mini');?>?id="+id,function(e){
      if(e.code == 3){
        layer.alert(e.msg);
      }
      if(e.code == 1){
        parent.location.href= e.url;
      }
      if(e.code == 2){
        layer.confirm('您还没有授权，是否授权？', {
            btn: ['确认', '取消']
            ,btn2: function(index, layero){
              //请求后台关闭session
              $.get("<?php echo U('Shop/mini');?>?session=1",function(data){});
              layer.close(index);
            }
          }, function(index, layero){
            parent.location.href= e.url;
          }
        )
      }
    });

  })

  $("#add").click(function(event) {
    layer.open({
      type: 2,
      title: '添加商家',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      area: ['800px', '600px'],
      content: '<?php echo U("add");?>'
    });
  });
  $("#view").on('click', '.edit', function(event) {
    var id = $(this).data('id');
    layer.open({
      type: 2,
      title: '编辑商家',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      area: ['800px', '600px'],
      content: '<?php echo U("edit");?>?id='+id
    });
  });
  $("#view").on('click', '.setType', function(event) {
    var id = $(this).data('id');
    layer.open({
      type: 2,
      title: '修改模板',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      area: ['450px', '300px'],
      content: '<?php echo U("type");?>?id='+id
    });
  });
  $("#view").on('click', '.tong', function(event) {
    var id = $(this).data('id');
    $.post("<?php echo U('audit_shop');?>", {shop_id: id}, function(e) {
      if(e.status == 1){
        layer.msg(e.info,{icon: 6,time:1000});
        setTimeout("location.reload()",1000);
      }else{
        layer.msg(e.info,{icon:1,time:1000});
      }
    });
  });

  getList(1, 10, '', '');

  function getList(page, limit, sCont, sType){
    var cont = document.getElementById("search-snames").value;
    $.get("<?php echo U('index');?>?page="+page+"&limit="+ limit + sCont + sType,function(data){
      var view = document.getElementById('view');
      var getTpl = tpl.innerHTML;
      laytpl(getTpl).render(data.list, function(html){
        view.innerHTML = html;
      });
      laypage.render({
        elem: 'page-box'
        ,count: data.count
        ,curr: page
        ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
        ,jump: function(obj, first){
          console.log(obj)
          if(!first){
            getList(obj.curr, obj.limit);
          }
        }
      });
    })
  }
  $("#search-butt").on('click', function () {
    var cont = document.getElementById("search-snames").value;
    var type = document.getElementById("search-selsct").value;
    console.log(cont + "--" + type);

    getList(1, 10, '&sCont=' + cont, '&sType=' + type);
  })
  
});
</script>
</body>
</html>